#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author   : Moty
# @Time     : 2024/10/18 22:39
# @File     : kc16_43.py
# @Project  : CSPT
def parse_43_Offline_Card_Data_Response(body):
    # 解析0x41 余额更新应答
    data = {
        "桩编号": f"{body[0:14]}({body[0:14]})",
        "保存结果": f"{save_result(body[14:16])}({body[14:16]})",
        "失败原因": f"{fail_reason(body[16:18])}({body[16:18]})",
    }
    formatted_data = ""
    for key, value in data.items():
        formatted_data += f"{key}: {value}\n"
    return formatted_data


def save_result(result):
    return "失败" if result == "00" else "成功" if result == "01" else "未知"


def fail_reason(result):
    return "卡号格式错误" if result == "01" else "储存空间不足" if result == "02" else "未知"


__all__ = ['parse_43_Offline_Card_Data_Response']
